home *** CD-ROM | disk | FTP | other *** search
/ PC Answers 1995 May / PC Answers CD-ROM 7 (Future Publishing) (May 1995).iso / vbits / code / zuck / combine.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1994-10-06  |  8.1 KB  |  241 lines

  1. VERSION 2.00
  2. Begin Form Combine 
  3.    Caption         =   "Combining Images"
  4.    ClientHeight    =   4200
  5.    ClientLeft      =   1095
  6.    ClientTop       =   1485
  7.    ClientWidth     =   5790
  8.    Height          =   4605
  9.    Left            =   1035
  10.    LinkTopic       =   "Form3"
  11.    ScaleHeight     =   4200
  12.    ScaleWidth      =   5790
  13.    Top             =   1140
  14.    Width           =   5910
  15.    Begin PictureBox picSaved 
  16.       Height          =   510
  17.       Left            =   420
  18.       ScaleHeight     =   480
  19.       ScaleWidth      =   480
  20.       TabIndex        =   14
  21.       Top             =   2760
  22.       Width           =   510
  23.    End
  24.    Begin PictureBox picWork3 
  25.       Height          =   510
  26.       Left            =   3600
  27.       ScaleHeight     =   480
  28.       ScaleWidth      =   480
  29.       TabIndex        =   12
  30.       Top             =   3420
  31.       Width           =   510
  32.    End
  33.    Begin PictureBox picWork2 
  34.       Height          =   510
  35.       Left            =   3600
  36.       ScaleHeight     =   480
  37.       ScaleWidth      =   480
  38.       TabIndex        =   10
  39.       Top             =   2820
  40.       Width           =   510
  41.    End
  42.    Begin PictureBox picWork 
  43.       Height          =   510
  44.       Left            =   3600
  45.       ScaleHeight     =   480
  46.       ScaleWidth      =   480
  47.       TabIndex        =   9
  48.       Top             =   2220
  49.       Width           =   510
  50.    End
  51.    Begin CommandButton cmdClose 
  52.       Caption         =   "Close"
  53.       Height          =   435
  54.       Left            =   2220
  55.       TabIndex        =   4
  56.       Top             =   3600
  57.       Width           =   1095
  58.    End
  59.    Begin PictureBox picCarMaskI 
  60.       AutoRedraw      =   -1  'True
  61.       Height          =   510
  62.       Left            =   3600
  63.       ScaleHeight     =   480
  64.       ScaleWidth      =   480
  65.       TabIndex        =   3
  66.       Top             =   1560
  67.       Width           =   510
  68.    End
  69.    Begin PictureBox picCarMask 
  70.       AutoRedraw      =   -1  'True
  71.       AutoSize        =   -1  'True
  72.       Height          =   510
  73.       Left            =   3600
  74.       Picture         =   COMBINE.FRX:0000
  75.       ScaleHeight     =   480
  76.       ScaleWidth      =   480
  77.       TabIndex        =   2
  78.       Top             =   960
  79.       Width           =   510
  80.    End
  81.    Begin PictureBox picCar 
  82.       AutoSize        =   -1  'True
  83.       Height          =   510
  84.       Left            =   3600
  85.       Picture         =   COMBINE.FRX:027A
  86.       ScaleHeight     =   480
  87.       ScaleWidth      =   480
  88.       TabIndex        =   1
  89.       Top             =   360
  90.       Width           =   510
  91.    End
  92.    Begin PictureBox picLeafs 
  93.       AutoSize        =   -1  'True
  94.       Height          =   2280
  95.       Left            =   420
  96.       MousePointer    =   2  'Cross
  97.       Picture         =   COMBINE.FRX:04F4
  98.       ScaleHeight     =   150
  99.       ScaleMode       =   3  'Pixel
  100.       ScaleWidth      =   200
  101.       TabIndex        =   0
  102.       Top             =   360
  103.       Width           =   3030
  104.    End
  105.    Begin Label Label7 
  106.       Caption         =   "Hold the original image segment to restore later."
  107.       Height          =   675
  108.       Left            =   1080
  109.       TabIndex        =   15
  110.       Top             =   2760
  111.       Width           =   1935
  112.    End
  113.    Begin Label Label6 
  114.       Caption         =   "Work area - step 3"
  115.       Height          =   435
  116.       Left            =   4200
  117.       TabIndex        =   13
  118.       Top             =   3420
  119.       Width           =   1275
  120.    End
  121.    Begin Label Label5 
  122.       Caption         =   "Work area - step 2"
  123.       Height          =   435
  124.       Left            =   4200
  125.       TabIndex        =   11
  126.       Top             =   2820
  127.       Width           =   1275
  128.    End
  129.    Begin Label Label4 
  130.       Caption         =   "Work area - step 1"
  131.       Height          =   375
  132.       Left            =   4200
  133.       TabIndex        =   8
  134.       Top             =   2280
  135.       Width           =   1395
  136.    End
  137.    Begin Label Label3 
  138.       Caption         =   "Inverted mask - created at runtime."
  139.       Height          =   615
  140.       Left            =   4200
  141.       TabIndex        =   7
  142.       Top             =   1560
  143.       Width           =   1395
  144.    End
  145.    Begin Label Label2 
  146.       Caption         =   "Mask to use."
  147.       Height          =   495
  148.       Left            =   4200
  149.       TabIndex        =   6
  150.       Top             =   960
  151.       Width           =   1395
  152.    End
  153.    Begin Label Label1 
  154.       Caption         =   "Picture to combine."
  155.       Height          =   495
  156.       Left            =   4200
  157.       TabIndex        =   5
  158.       Top             =   360
  159.       Width           =   1395
  160.    End
  161. Option Explicit
  162. ' We use these variables to keep track of whether the
  163. ' car is currently merged, and if so, where.
  164. Dim CarIsMerged%
  165. Dim CarMergeLocX%
  166. Dim CarMergeLocY%
  167. Sub cmdClose_Click ()
  168.     Unload Me
  169. End Sub
  170. ' This routine combines the car into the leaf spread
  171. ' x and y are the start position for the merge in the leaf
  172. ' picture
  173. ' We'll use x = -1000 to indicate that the existing car
  174. ' location should be cleared.
  175. Sub CombineImage (X%, Y%)
  176.     Dim di%
  177.     If CarIsMerged% Then
  178.         ' Car is already merged - we had better remove
  179.         ' it before merging it into the new location
  180.         ' This is accomplished by simply restoring
  181.         ' the saved area.
  182.         di% = BitBlt(picLeafs.hDC, CarMergeLocX%, CarMergeLocY%, 32, 32, picSaved.hDC, 0, 0, SRCCOPY)
  183.         CarIsMerged% = False
  184.     End If
  185.     If X% = -1000 Then Exit Sub
  186.     ' Lets start by bringing in a portion of the leaf
  187.     ' spread into the work picture.
  188.     di% = BitBlt(picWork.hDC, 0, 0, 32, 32, picLeafs.hDC, X%, Y%, SRCCOPY)
  189.     ' We'll also hold the image in the saved area
  190.     di% = BitBlt(picSaved.hDC, 0, 0, 32, 32, picLeafs.hDC, X%, Y%, SRCCOPY)
  191.     ' In a real application, we would perform all of the
  192.     ' following operations on the same work picture.
  193.     ' For illustrative purposes, we're using multiple
  194.     ' pictures.
  195.     ' Now lets Force to white the car area
  196.     ' First bring over the current work area.
  197.     di% = BitBlt(picWork2.hDC, 0, 0, 32, 32, picWork.hDC, 0, 0, SRCCOPY)
  198.     ' Now OR in the inverted mask
  199.     di% = BitBlt(picWork2.hDC, 0, 0, 32, 32, picCarMaskI.hDC, 0, 0, SRCPAINT)
  200.     ' Now lets merge in the car
  201.     ' First, bring over the current work area.
  202.     di% = BitBlt(picWork3.hDC, 0, 0, 32, 32, picWork2.hDC, 0, 0, SRCCOPY)
  203.     ' Now AND in the car picture
  204.     di% = BitBlt(picWork3.hDC, 0, 0, 32, 32, picCar.hDC, 0, 0, SRCAND)
  205.     ' And finally,  Copy the bitmap back to the original spread
  206.     di% = BitBlt(picLeafs.hDC, X%, Y%, 32, 32, picWork3.hDC, 0, 0, SRCCOPY)
  207.     ' Save the current status
  208.     CarIsMerged% = True
  209.     CarMergeLocX% = X%
  210.     CarMergeLocY% = Y%
  211. End Sub
  212. Sub Form_Load ()
  213.     Dim di%
  214.     ' Note that in order for this BitBlt to work during
  215.     ' form load, both of these picture controls must have
  216.     ' autoredraw set to True - this assures that the
  217.     ' device context refers to a real bitmap at all times.
  218.     di% = BitBlt(picCarMaskI.hDC, 0, 0, 32, 32, picCarMask.hDC, 0, 0, SRCINVERT)
  219. End Sub
  220. Sub Form_MouseMove (Button As Integer, Shift As Integer, X As Single, Y As Single)
  221.     CombineImage -1000, -1000
  222. End Sub
  223. Sub picLeafs_MouseMove (Button As Integer, Shift As Integer, X As Single, Y As Single)
  224.     Dim usex%, usey%
  225.     ' It's safe to use integers here, as we've set the
  226.     ' scalemode to pixels.
  227.     usex% = X
  228.     usey% = Y
  229.     ' Rather than go through the hassle of partial bitmaps,
  230.     ' we'll simply restrict the merge area to valid parts
  231.     ' of the leaf picture control
  232.     ' Important:  We know that we're using a 32x32 pixel
  233.     ' merge field.  A robust version of this program would
  234.     ' have to calculate the actual size of the merged image
  235.     If usex% < 0 Then usex% = 0
  236.     If usey% < 0 Then usey% = 0
  237.     If usex% + 32 > picLeafs.ScaleWidth Then usex% = picLeafs.ScaleWidth - 32
  238.     If usey% + 32 > picLeafs.ScaleHeight Then usey% = picLeafs.ScaleHeight - 32
  239.     CombineImage usex%, usey%
  240. End Sub
  241.